package org.xhnews.ui;

import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.GUIControl;
import javax.microedition.media.control.VideoControl;

import org.xhnews.log.RaspberryLogger;

import net.rim.device.api.ui.Field;

import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;

public class VideoPlayerScreen extends MainScreen {
	private Player player;
	private VideoControl vc;
	private String _url;
	public VideoPlayerScreen(String url) {
		_url=url;
		LabelField title = new LabelField("Video Playback Sample",
				LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
		setTitle(title);		
		add(new RichTextField("Playing video in window", Field.NON_FOCUSABLE));
		try {
			player = Manager.createPlayer(_url);
			player.realize();
			vc = (VideoControl) player.getControl("VideoControl");
			vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
			GUIControl gc;
			if ((gc = (GUIControl) player.getControl("GUIControl")) != null)
				add((Field) gc.initDisplayMode(GUIControl.USE_GUI_PRIMITIVE,
						null));
			vc.setDisplayFullScreen(true); 
			vc.setVisible(true);
			player.start();
		} catch (Exception e) {
			RaspberryLogger.getInstance().error(e);
		}
	}
	public void initialize(String url){
		_url=url;
	}
}
